import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login.vue')
    },
    {
      path: '/expert',
      component: () => import('@/views/expert/ExpertLayout.vue'),
      meta: { requiresAuth: true, role: 'expert' },
      children: [
        {
          path: '',
          redirect: 'inquiry-form'
        },
        {
          path: 'home',
          component: () => import('@/views/expert/ExpertHome.vue')
        },
        {
          path: 'list',
          name: 'expert-inquiry-list',
          component: () => import('@/views/expert/InquiryList.vue')
        },
        {
          path: 'inquiry-form',
          component: () => import('@/views/expert/InquiryForm.vue')
        },
        {
          path: 'inquiryDetail',
          name: 'expert-inquiry-detail',
          component: () => import('@/views/expert/InquiryDetail.vue')
        },
      ]
    },
    {
      path: '/bidder',
      component: () => import('@/views/bidder/BidderLayout.vue'),
      meta: { requiresAuth: true, role: 'bidder' },
      children: [
        {
          path: '',
          redirect: 'inquiries'
        },
        {
          path: 'inquiries',
          name: 'bidder-inquiries',
          component: () => import('@/views/bidder/InquiryList.vue')
        },
        {
          path: 'home',
          name: 'bidder-home',
          component: () => import('@/views/bidder/BidderHome.vue')
        }
      ]
    },
    {
      path: '/admin',
      component: () => import('@/views/admin/AdminLayout.vue'),
      meta: { requiresAuth: true, role: 'admin' },
      children: [
        {
          path: '',
          redirect: 'dashboard'
        },
        {
          path: 'dashboard',
          name: 'admin-dashboard',
          component: () => import('@/views/admin/Dashboard.vue')
        },
        
        {
          path: 'inquiries',
          name: 'admin-inquiries',
          component: () => import('@/views/admin/InquiryRecords.vue')
        },
        {
          path: 'messagestemplate',
          name: 'admin-messagestemplate',
          component: () => import('@/views/admin/MessageTempalte.vue')
        },
        {
          path: 'paramconfig',
          name: 'paramconfig',
          component: () => import('@/views/admin/ParamConfig.vue')  
        },
        {
          path: 'logs/login',
          name: 'loginlog',
          component: () => import('@/views/admin/LoginLog.vue')  
        },
        {
          path: 'logs/operation',
          name: 'inquiryopertionlog',
          component: () => import('@/views/admin/InquiryOpertionLog.vue')  
        },
        {
          path: 'logs/system',
          name: 'viewlog',
          component: () => import('@/views/admin/ViewLog.vue')  
        },
      ]
    },
    {
      path: '/test/style',
      name: 'style-test',
      component: () => import('@/views/test/StyleTest.vue')
    },
    {
      path: '*',
      name: 'not-found',
      component: () => import('@/views/NotFound.vue')
    }
  ]
})

// 导航守卫（已临时简化，避免在 App 初始化前访问 Pinia 导致报错）
router.beforeEach((to, from, next) => {
  next()
})

export default router